package com.tianpengtech.admin.fairorder;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;

import com.jfinal.plugin.activerecord.Model;
import com.tianpengtech.common.exception.ValidateException;
import com.tianpengtech.admin.AbstractAdmin;
import com.tianpengtech.common.model.authenticate.Authenticate;
import com.tianpengtech.common.model.fairorder.FairOrder;
import com.tianpengtech.common.search.EqualCondition;
import com.tianpengtech.common.search.LikeCondition;
import com.tianpengtech.common.search.QueryConstructor;


public class FairOrderAdminServiceImpl extends AbstractAdmin{

	@Override
	public void beforeAdd(Model<?> model) throws ValidateException {

	}

	@Override
	public void beforeQueryById(Model<?> model, int id) {

	}

	@Override
	public void beforeUpdate(Model<?> model) throws ValidateException {

	}

	@Override
	public void beforeDelete(Model<?> model) {

	}

	@Override
	public void builderSQLExpected(Model< ? > model,
			QueryConstructor queryConstruct, Map< String, Object > params) {

		
		setQuerySQLCommand("select t1.*,t2.company_name ");
		queryConstruct.setCommand(" from "+FairOrder.dao.tableName()+" as t1,"+Authenticate.dao.tableName()+" as t2 where t1.user=t2.user_id");
		setOrderClause(" order by t1.id desc");
		int status = model.getInt(FairOrder.STATUS);
		String user = model.getStr(FairOrder.XML_CONTENT);
		if(status>-1){
			queryConstruct.and(new EqualCondition(" and t1.status ", status));
		}
		if(StringUtils.isNotEmpty(user)){
			queryConstruct.and(new LikeCondition(" and t2.company_name ", "%"+user+"%"));
		}
	}

	@Override
	public String tableName() {
		return FairOrder.dao.tableName();
	}

}